﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AssettDatabase
{
    public partial class Form_Sel_Supplier : Form
    {
        public string retSupplier_ID { get; set; } 
        public Form_Sel_Supplier()
        {
            InitializeComponent();
        }

        private void Form_Sel_Supplier_Load(object sender, EventArgs e)
        {
            BLL.Supplier bllSupplier = new BLL.Supplier();
            gridSupplier.DataSource = bllSupplier.GetSupplier();
        }

        private void TB_SupplierName_KeyUp(object sender, KeyEventArgs e)
        {
            BLL.Supplier bllSupplier = new BLL.Supplier();
            List<VO.Supplier> filterData = new List<VO.Supplier>();
            if (TB_SupplierName.Text.Length == 0)
                filterData = bllSupplier.GetSupplier();
            else
                filterData = (from s in bllSupplier.GetSupplier() where s.Supplier_Name.ToLower().Contains(TB_SupplierName.Text.ToLower()) select s).ToList();

            gridSupplier.DataSource = filterData;
        }

        private void gridSupplier_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                this.retSupplier_ID = gridSupplier.Rows[e.RowIndex].Cells["Supplier_ID"].Value.ToString();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
